//
//  HDactivityRulesView.m
//  HDVideoKitDemok
//
//  Created by ^-^ on 2020/12/2.
//

#import "HDactivityRulesView.h"
#import "Macro.h"

@interface HDactivityRulesView ()
@property (strong, nonatomic) UIButton *decorateButton;
@property (strong, nonatomic) UIView *bgView;
@property (strong, nonatomic) UIButton *closeButton;

@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UIView *contentView;

@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *subtitleLabel;
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *contentLabel;

@property (strong, nonatomic) UILabel *nameLabel1;
@property (strong, nonatomic) UILabel *contentLabel1;


@end

@implementation HDactivityRulesView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = RGBA(0, 0, 0, 0.6);
        
        self.bgView = [[UIView alloc]init];
        self.bgView.backgroundColor = [UIColor whiteColor];
        self.bgView.layer.cornerRadius = 15;
        self.bgView.layer.masksToBounds = YES;
        [self addSubview:self.bgView];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.width.mas_equalTo(324);
            make.height.mas_equalTo(357);
        }];
        
        self.decorateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.decorateButton  setBackgroundImage:[UIImage imageNamed:HDBundleImage(@"video/img_head")] forState:UIControlStateNormal];
        [self.decorateButton setTitle:@"抽奖" forState:UIControlStateNormal];
        [self.decorateButton setTitleColor:RGBA(50, 60, 67, 1) forState:UIControlStateNormal];
        self.decorateButton.titleLabel.font = [UIFont systemFontOfSize:16];
        self.decorateButton.userInteractionEnabled = NO;
        [self addSubview:self.decorateButton];
        [self.decorateButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.top.equalTo(self.bgView.mas_top).offset(-21);
            make.width.mas_equalTo(self.decorateButton.currentBackgroundImage.size.width);
            make.height.mas_equalTo(self.decorateButton.currentBackgroundImage.size.height);
        }];
        
        self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.closeButton setImage:[UIImage imageNamed:HDBundleImage(@"video/btn_x")] forState:UIControlStateNormal];
        [self.closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.closeButton];
        [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgView.mas_right).offset(-4);
            make.top.equalTo(self.bgView.mas_top).offset(4);
            make.width.mas_equalTo(26);
            make.height.mas_equalTo(26);
        }];
        self.scrollView = [[UIScrollView alloc]init];
        [self.bgView addSubview:self.scrollView];
        [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bgView.mas_top).offset(45);
            make.left.equalTo(self.bgView.mas_left).offset(20);
            make.right.equalTo(self.bgView.mas_right).offset(-20);
            make.bottom.equalTo(self.bgView.mas_bottom).offset(-20);
        }];
        self.contentView = [[UIView alloc]init];
        [self.scrollView addSubview:self.contentView];
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.scrollView);
            make.width.mas_equalTo(self.scrollView);
        }];

    }
    return self;
}

-(void)setDic:(NSDictionary *)dic {
    _dic = dic;
    
    self.titleLabel = [[UILabel alloc]init];
    if ([dic[@"name"] isKindOfClass:[NSString class]]) {
        self.titleLabel.text = dic[@"name"];
    }
    self.titleLabel.textColor = RGBA(57, 60, 67, 1);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.contentView.mas_left).offset(24);
        make.right.equalTo(self.contentView.mas_right).offset(-24);
        make.height.mas_equalTo(22);
    }];

    
    self.subtitleLabel = [[UILabel alloc]init];
    self.subtitleLabel.text = @"活动规则及奖品";
    self.subtitleLabel.textColor = RGBA(57, 60, 67, 1);
    self.subtitleLabel.textAlignment = NSTextAlignmentCenter;
    self.subtitleLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.subtitleLabel];
    [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(2);
        make.left.equalTo(self.contentView.mas_left).offset(24);
        make.right.equalTo(self.contentView.mas_right).offset(-24);
        make.height.mas_equalTo(20);
    }];
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.text = @"活动规则";
    self.nameLabel.textColor = RGBA(57, 60, 67, 0.76);
    self.nameLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.subtitleLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(20);
    }];
    
    self.contentLabel = [[UILabel alloc]init];
    self.contentLabel.textColor = RGBA(57, 60, 67, 1);
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    if ([dic[@"rule"] isKindOfClass:[NSString class]]) {
//        self.contentLabel.text = @"222";
        self.contentLabel.text = dic[@"rule"];
    }
    [self.contentView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(8);
    }];
    self.nameLabel1 = [[UILabel alloc]init];
    self.nameLabel1.text = @"奖品说明";
    self.nameLabel1.textColor = RGBA(57, 60, 67, 0.76);
    self.nameLabel1.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.nameLabel1];
    [self.nameLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(20);
    }];
    
    self.contentLabel1 = [[UILabel alloc]init];
    self.contentLabel1.numberOfLines = 0;
    self.contentLabel1.textColor = RGBA(57, 60, 67, 1);;
    self.contentLabel1.font = [UIFont systemFontOfSize:14];
    if ([dic[@"description"] isKindOfClass:[NSString class]]) {
//        self.contentLabel1.text = @"222";
        self.contentLabel1.text = dic[@"description"];
    }
    [self.contentView addSubview:self.contentLabel1];
    [self.contentLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.nameLabel1.mas_bottom).offset(8);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentLabel1.mas_bottom).offset(20);
    }];
    

    

    

    

}


- (void)closeAction {
    [self removeFromSuperview];
}
@end
